# include "GetDataFilter.h"

extern "C" {
# include "libavformat/avformat.h"
}

GetDataFilter::GetDataFilter()
{
}

uint8_t* GetDataFilter::getVideoData() const
{
	return this->m_video_data;
}

size_t GetDataFilter::getVideoDataSize() const
{
	return this->m_video_data_size;
}

uint8_t* GetDataFilter::getAudioData() const
{
	return this->m_audio_data;
}

size_t GetDataFilter::getAudioDataSize() const
{
	return this->m_audio_data_size;
}

void GetDataFilter::afterVideoEncode(AVPacket* _packet)
{
	if (_packet->size != this->m_video_data_size) {
		this->m_video_data_size = _packet->size;
		delete[] this->m_video_data;
		this->m_video_data = new uint8_t[this->m_video_data_size];
	}
	memcpy_s(this->m_video_data, _packet->size, _packet->data, _packet->size);
	EncoderFilter::afterVideoEncode(_packet);
}

void GetDataFilter::afterAudioEncode(AVPacket* _packet)
{
	if (_packet->size > this->m_audio_data_size) {
		this->m_audio_data_size = _packet->size;
		delete[] this->m_audio_data;
		this->m_audio_data = new uint8_t[this->m_audio_data_size];
	}
	memcpy_s(this->m_audio_data, _packet->size, _packet->data, _packet->size);
	EncoderFilter::afterAudioEncode(_packet);
}

GetDataFilter::~GetDataFilter()
{
	delete[] this->m_video_data;
	delete[] this->m_audio_data;
}
